<script type="text/javascript">
    var userStoreDomainNameValid = true;
    var userStoreHostValid = true;
    var userStorePortValid = true;
    var userStoreRootSuffixValid = true;
    var userStoreLoginIdValid = true;
    var userStorePasswordValid = false;
 
    function allValid() {
        var allFieldsValid = (userStoreHostValid && userStorePortValid &&
            userStoreRootSuffixValid && userStoreLoginIdValid &&
            userStorePasswordValid);
       
        if (allFieldsValid) {
            ie7fix++;
            AjaxUtils.call("$context$path?actionLink=validateUMHost&ie7fix=" + ie7fix,
                validateUMHost);
        } else {
            $('nextTabButton').disabled = true;
        }
    }

    function adValid() {
        var adFieldsValid = (userStoreDomainNameValid && 
            userStoreLoginIdValid &&
            userStorePasswordValid);
       
        if (adFieldsValid) {
            ie7fix++;
            AjaxUtils.call("$context$path?actionLink=validateUMDomainName&ie7fix=" + ie7fix, validateUMDomainName);
        } else {
            $('nextTabButton').disabled = true;
        }
    }

    function validateUMDomainName(response) {
        if (response.responseText == "ok") { 
            $('nextTabButton').disabled = false;
            $('userStoreDomainNameStatus').innerHTML = "";
        } else {
            $('nextTabButton').disabled = true;
            $('userStoreDomainNameStatus').innerHTML = errorImage +
                '<small>' + response.responseText + '</small>';
        }
    }

    function validateUMHost(response) {
        if (response.responseText == "ok") { 
            $('nextTabButton').disabled = false;
            $('userStoreHostStatus').innerHTML = "";
        } else {
            $('nextTabButton').disabled = true;
            $('userStoreHostStatus').innerHTML = errorImage +
                '<small>' + response.responseText + '</small>';
        }
    }
    
    function validateADUserFields(response) {
        if (response.responseText == "ok") { 
	    eval(field + "Valid = true;" );
            $(field + 'Status').innerHTML = okString;
            if (field == "ADuserStorePassword") {
                userStorePasswordValid = true;
            }
            adValid();
        } else {
            eval(field + "Valid = false;" );
            $(field + 'Status').innerHTML = errorImage +
                '<small>' + response.responseText + '</small>';
        }                
        field = "";
    }

    function validateUserFields(response) {
        if (response.responseText == "ok") { 
	    eval(field + "Valid = true;" );
            $(field + 'Status').innerHTML = okString;
            allValid();
        } else {
            eval(field + "Valid = false;" );
            $('nextTabButton').disabled = true;
            $(field + 'Status').innerHTML = errorImage +
                '<small>' + response.responseText + '</small>';
        }                
        field = "";
    }  

    function validateUserStoreSSL() {
        field = "userStoreSSL";
        var callUrl = "$context$path?actionLink=setSSL";
        var value = ($('userStoreSSL').checked) ? "SSL" : "SIMPLE";
        var param = "&ssl=" + value;
        ie7fix++;
        callUrl = callUrl + "&ie7fix=" + ie7fix;
        AjaxUtils.call(callUrl+param, validateSSLField);
    }

    function validateSSLField() {
        allValid();
    }

    function validateADUserStoreSSL() {
        field = "ADuserStoreSSL";
        var callUrl = "$context$path?actionLink=setSSL";
        var value = ($('ADuserStoreSSL').checked) ? "SSL" : "SIMPLE";
        var param = "&ssl=" + value;
        ie7fix++;
        callUrl = callUrl + "&ie7fix=" + ie7fix;
        AjaxUtils.call(callUrl+param, validateADSSLField);
    }

    function validateADSSLField() {
        adValid();
    }

    function validateUserStoreDomainName() {
        field = "userStoreDomainName";
        var callUrl = "$context$path?actionLink=setDomainName";
        var param = "&domainname=" + $('userStoreDomainName').value;
        ie7fix++;
        callUrl = callUrl + "&ie7fix=" + ie7fix;
        AjaxUtils.call(callUrl+param, validateADUserFields);
    }         

    function validateADUserStoreLoginId() {
        field = "ADuserStoreLoginId";
        var callUrl = "$context$path?actionLink=setLoginID";
        var param = "&dn=" + $('ADuserStoreLoginId').value;
        ie7fix++;
        callUrl = callUrl + "&ie7fix=" + ie7fix;
        AjaxUtils.call(callUrl+param, validateADUserFields);
    }    

    function validateADUserStorePassword() {
        field = "ADuserStorePassword";
        var callUrl = "$context$path?actionLink=setPassword";
        var param = "password=" + encodeURIComponent($('ADuserStorePassword').value);
        ie7fix++;
        callUrl = callUrl + "&ie7fix=" + ie7fix;
        AjaxUtils.doPost(null, callUrl, param, validateADUserFields, 
            null, null);
    }   

    function validateUserStoreHost() {
        field = "userStoreHost";
        var callUrl = "$context$path?actionLink=setHost";
        var param = "&host=" + $('userStoreHost').value;
        ie7fix++;
        callUrl = callUrl + "&ie7fix=" + ie7fix;
        AjaxUtils.call(callUrl+param, validateUserFields);
    }         
    
    function validateUserStorePort() {
        field = "userStorePort";
        var callUrl = "$context$path?actionLink=setPort";
        var param = "&port=" + $('userStorePort').value;
        ie7fix++;
        callUrl = callUrl + "&ie7fix=" + ie7fix;
        AjaxUtils.call(callUrl+param, validateUserFields);
    }       

    function validateUserStoreRootSuffix() {
        field = "userStoreRootSuffix";
        var callUrl = "$context$path?actionLink=setRootSuffix";
        var param = "&rootsuffix=" + encodeURIComponent($('userStoreRootSuffix').value);
        ie7fix++;
        callUrl = callUrl + "&ie7fix=" + ie7fix;
        AjaxUtils.call(callUrl+param, validateUserFields);
    }
    
    function validateUserStoreLoginId() {
        field = "userStoreLoginId";
        var callUrl = "$context$path?actionLink=setLoginID";
        var param = "&dn=" + $('userStoreLoginId').value;
        ie7fix++;
        callUrl = callUrl + "&ie7fix=" + ie7fix;
        AjaxUtils.call(callUrl+param, validateUserFields);
    }    

    function validateUserStorePassword() {
        field = "userStorePassword";
        var callUrl = "$context$path?actionLink=setPassword";
        var param = "password=" + encodeURIComponent($('userStorePassword').value);
        ie7fix++;
        callUrl = callUrl + "&ie7fix=" + ie7fix;
        AjaxUtils.doPost(null, callUrl, param, validateUserFields, null, null);
    }   
    
    function setADforDomainName() {
        setType(document.getElementById("ldapv3adforDomainName").value);
        document.getElementById("activeDirectoryConfigSettings").style.display = "";
        document.getElementById("embeddedConfigSettings").style.display = "none";
        document.getElementById("userStoreSettings").style.display = "none";
        ie7fix++;
        AjaxUtils.call("$context$path?actionLink=resetUMEmbedded&ie7fix=" + ie7fix);
    }

    function setAD() {
        setType(document.getElementById("ldapv3ad").value);
        document.getElementById("userStoreSettings").style.display = "";
        document.getElementById("activeDirectoryConfigSettings").style.display = "none";
    }

    function setADAM() {
        setType(document.getElementById("ldapv3adam").value);
        document.getElementById("userStoreSettings").style.display = "";
        document.getElementById("activeDirectoryConfigSettings").style.display = "none";
    }

    function setODSEE() {
        setType(document.getElementById("ldapv3odsee").value);
        document.getElementById("userStoreSettings").style.display = "";
        document.getElementById("activeDirectoryConfigSettings").style.display = "none";
    }

    function setOpenDS() {
        setType(document.getElementById("ldapv3opends").value);
        document.getElementById("userStoreSettings").style.display = "";
        document.getElementById("activeDirectoryConfigSettings").style.display = "none";
    }

    function setTivoli() {
        setType(document.getElementById("ldapv3tivoli").value);
        document.getElementById("userStoreSettings").style.display = "";
        document.getElementById("activeDirectoryConfigSettings").style.display = "none";
    }

    function setType(type) {
        var callUrl = "$context$path?actionLink=setStoreType";
        ie7fix++;
        callUrl = callUrl + "&ie7fix=" + ie7fix;
        AjaxUtils.call(callUrl + "&type=" + type);
    }
    
    <!-- when embedded user config is selected -->
    function enableEmbeddedConfig() {
        userStoreChoice = "embedded";
        document.getElementById("embeddedConfigSettings").style.display = "";
        document.getElementById("externalConfigSettings").style.display = "none";        
        document.getElementById("activeDirectoryConfigSettings").style.display = "none";
        $('nextTabButton').disabled = false;
        ie7fix++;
        AjaxUtils.call("$context$path?actionLink=setUMEmbedded&ie7fix=" + ie7fix);
    }
    
    <!-- when external config is selected -->
    function enableExternalConfig() {
        userStoreChoice = "external";
        document.getElementById("ldapv3opends").checked=true;
        document.getElementById("externalConfigSettings").style.display = "";
        document.getElementById("userStoreSettings").style.display = "";
        document.getElementById("activeDirectoryConfigSettings").style.display = "none";
        document.getElementById("embeddedConfigSettings").style.display = "none";
        allValid();
        ie7fix++;
        AjaxUtils.call("$context$path?actionLink=resetUMEmbedded&ie7fix=" + ie7fix);
    }
    
    function initUserStorePage() {
        if ( "$EXT_DATA_STORE" == "true" ) {
            enableExternalConfig();
        } else {
            enableEmbeddedConfig();
        }
    }
        
    YAHOO.util.Event.onDOMReady(initUserStorePage);
</script>

<div style="margin-left:10px;">
    <h1>$page.getLocalizedString("step4.title")<img class="pointer" src="$context/assets/images/message.gif"/></h1>
    <p>$page.getLocalizedString("step4.description")</p>

    <label for="userStoreDefault" style="float:none">
        <input type="radio" id="userStoreDefault" name="userStoreCustom"
            style="margin-left:1em" value="false" $selectEmbeddedUM
            $radioDataTypeDisabled onclick="enableEmbeddedConfig();"/>
        <span>$page.getLocalizedString("configurator.embedded")</span><br/>
    </label>

    <label for="userStoreCustom" style="float:none">
        <input type="radio" id="userStoreCustom" name="userStoreCustom"
            style="margin-left:1em" value="true" $selectExternalUM
            $radioDataTypeDisabled onclick="enableExternalConfig();"/>
        <span>$page.getLocalizedString("configurator.remote")</span>
    </label>
    
    <div id="userStoreModule" style="width:610px;">
        <p id="allfields"><em>*</em>&nbsp;$page.getLocalizedString("required.field.label")</p>
        <b class="xtop">
            <b class="xt1"></b>
            <b class="xt2"></b>
            <b class="xt3"></b>
            <b class="xt4"></b>
        </b>
        <div class="headerBox">$page.getLocalizedString("step4.sub.title")</div>
        <div class="bodyBox" style="height:270px;">
            <div id="embeddedConfigSettings"
                style="margin-left:10px; display:none">
                <br>
                <img src="$context/assets/images/error.jpg">&nbsp;
                <b>$page.getLocalizedString("embedded.user.message")</b>
            </div>
            <span id="externalConfigSettings" style="display:none">
                <table class="temp" style="margin-bottom: 0">
                    <tr>
                        <td valign="top"><em>*&nbsp;</em>$page.getLocalizedString("store.type.label")</td>
                        <td>
                            <table id="userStoreCustomTypes">
                                <tr>
                                    <td><label for="ldapv3opends" style="float:none"><input type="radio" id="ldapv3opends" name="userStoreType" value="LDAPv3ForOpenDS" $selectLDAPv3opends onclick="setOpenDS();"/>&nbsp;$page.getLocalizedString("opends.ldap.schema")</label></td>
                                    <td><label for="ldapv3odsee" style="float:none"><input type="radio" id="ldapv3odsee" name="userStoreType" value="LDAPv3ForODSEE" $selectLDAPv3odsee onclick="setODSEE();"/>&nbsp;$page.getLocalizedString("odsee.ldap.schema")</label></td>
                                </tr>
                                <tr>
                                    <td><label for="ldapv3adforDomainName" style="float:none"><input type="radio" id="ldapv3adforDomainName" name="userStoreType" value="LDAPv3ForADDC" $selectLDAPv3addc onclick="setADforDomainName();"/>&nbsp;$page.getLocalizedString("activedirectoryfordomainname.ldap.schema")</label></td>
                                    <td><label for="ldapv3ad" style="float:none"><input type="radio" id="ldapv3ad" name="userStoreType" value="LDAPv3ForAD" $selectLDAPv3ad onclick="setAD();"/>&nbsp;$page.getLocalizedString("activedirectory.ldap.schema")</label><br></td>
                                </tr>
                                <tr>
                                    <td><label for="ldapv3tivoli" style="float:none"><input type="radio" id="ldapv3tivoli" name="userStoreType" value="LDAPv3ForTivoli" $selectLDAPv3tivoli onclick="setTivoli();"/>&nbsp;$page.getLocalizedString("tivoli.ldap.schema")</label></td>
                                    <td><label for="ldapv3adam" style="float:none"><input type="radio" id="ldapv3adam" name="userStoreType" value="LDAPv3ForADAM" $selectLDAPv3adam onclick="setADAM();"/>&nbsp;$page.getLocalizedString("adam.ldap.schema")</label></td>
                                </tr>
                            </table>
                        </td>
                    </tr>            
                </table>
                <table class="temp" id="userStoreSettings" style="display:none">
                    <tr>
                        <td><label for="userStoreSSL"><em>*&nbsp;</em>$page.getLocalizedString("directory.ssl.label")</label></td>
                        <td>
                            <input id="userStoreSSL" name="userStoreSSL"
                                type="checkbox" value="SSL" $selectUserStoreSSL
                                onClick="APP.callDelayed(this, validateUserStoreSSL)"/>
                        </td>
                    </tr>
                    <tr>
                        <td><label for="userStoreHost"><em>*&nbsp;</em>$page.getLocalizedString("directory.name.label")</label></td>
                        <td>
                            <input id="userStoreHost" name="userStoreHost" type="text" 
                                   class="text" style="width:150px"  
                                   value="$userStoreHost"
                                   onkeyup="APP.callDelayed(this, validateUserStoreHost)"
                                   onchange="APP.callDelayed(this, validateUserStoreHost)"/>
                            <span id="userStoreHostStatus"></span>                       
                        </td>
                    </tr>
                    <tr>
                        <td><label for="userStorePort"><em>*&nbsp;</em>$page.getLocalizedString("port.label")</label></td>
                        <td>
                            <input id="userStorePort" name="userStorePort" 
                                   type="text" class="text" size="5" maxLength="5" 
                                   value="$userStorePort"
                                   onkeyup="APP.callDelayed(this, validateUserStorePort)"
                                   onchange="APP.callDelayed(this, validateUserStorePort)"/>
                            <span id="userStorePortStatus"></span>         
                        </td>
                    </tr>  
                    <tr>
                        <td><label for="userStoreRootSuffix"><em>*&nbsp;</em>$page.getLocalizedString("root.suffix.label")</label></td>
                        <td>
                            <input id="userStoreRootSuffix" name="userStoreRootSuffix" 
                                   type="text" class="text" style="width:200px"  
                                   value="$userStoreRootSuffix"
                                   onkeyup="APP.callDelayed(this, validateUserStoreRootSuffix)"
                                   onchange="APP.callDelayed(this, validateUserStoreRootSuffix)"/>
                            <span id="userStoreRootSuffixStatus"></span>    
                        </td>
                    </tr>
                    <tr>
                        <td><label for="userStoreLoginId"><em>*&nbsp;</em>$page.getLocalizedString("login.id.label")</label></td>
                        <td>
                            <input id="userStoreLoginId" name="userStoreLoginId" 
                                   type="text" class="text" style="width:150px" 
                                   value="$userStoreLoginId"
                                   onkeyup="APP.callDelayed(this, validateUserStoreLoginId)"
                                   onchange="APP.callDelayed(this, validateUserStoreLoginId)"/>
                            <span id="userStoreLoginIdStatus"></span>                             
                        </td>
                    </tr>
                    <tr>
                        <td><label for="userStorePassword"><em>*&nbsp;</em>$page.getLocalizedString("password.label")</label></td>
                        <td>
                            <input id="userStorePassword" name="userStorePassword" 
                                   type="password" class="text" style="width:100px" 
                                   onkeyup="APP.callDelayed(this, validateUserStorePassword )"
                                   onchange="APP.callDelayed(this, validateUserStorePassword )" />        
                             <span id="userStorePasswordStatus"></span>
                        </td>
                    </tr>
                </table>
            </span>
            <span id="activeDirectoryConfigSettings" style="display:none">
                <table class="temp">
                    <tr>
                        <td><label for="ADuserStoreSSL"><em>*&nbsp;</em>$page.getLocalizedString("directory.ssl.label")</label></td>
                        <td>
                            <input id="ADuserStoreSSL" name="ADuserStoreSSL"
                                type="checkbox" value="SSL" $selectADUserStoreSSL
                                onClick="APP.callDelayed(this, validateADUserStoreSSL)"/>
                        </td>
                    </tr>            
                    <tr>
                        <td><label for="userStoreDomainName"><em>*&nbsp;</em>$page.getLocalizedString("domain.name.label")</label></td>
                        <td>
                            <input id="userStoreDomainName" name="userStoreDomainName" type="text" 
                                   class="text" style="width:150px"  
                                   onkeyup="APP.callDelayed(this, validateUserStoreDomainName)"
                                   onchange="APP.callDelayed(this, validateUserStoreDomainName)"/>
                            <span id="userStoreDomainNameStatus"></span>                       
                        </td>
                    </tr>
                    <tr>
                        <td><label for="ADuserStoreLoginId"><em>*&nbsp;</em>$page.getLocalizedString("login.id.label")</label></td>
                        <td>
                            <input id="ADuserStoreLoginId" name="ADuserStoreLoginId" 
                                   type="text" class="text" style="width:150px" 
                                   onkeyup="APP.callDelayed(this, validateADUserStoreLoginId)"
                                   onchange="APP.callDelayed(this, validateADUserStoreLoginId)"/>
                            <span id="ADuserStoreLoginIdStatus"></span>                             
                        </td>
                    </tr>            
                    <tr>
                        <td><label for="ADuserStorePassword"><em>*&nbsp;</em>$page.getLocalizedString("password.label")</label></td>
                        <td>
                            <input id="ADuserStorePassword" name="ADuserStorePassword" 
                                   type="password" class="text" style="width:100px" 
                                   onkeyup="APP.callDelayed(this, validateADUserStorePassword )"
                                   onchange="APP.callDelayed(this, validateADUserStorePassword )" />        
                             <span id="ADuserStorePasswordStatus"></span>
                        </td>
                    </tr>
                </table>
            </span>
        </div>
        <div>
            <b class="xbottom">
                <b class="xbGray1"></b>
                <b class="xbGray2"></b>
                <b class="xbGray3"></b>
                <b class="xbGray4"></b>
            </b>
        </div>
    </div>
</div>
